﻿# coding=UTF-8
#from appengine_django.models import db.Model
from google.appengine.ext import db

class Archive(db.Model):
    monthyear = db.StringProperty(multiline=False)
    """July 2008"""
    weblogcount = db.IntegerProperty(default=0)
    date = db.DateTimeProperty(auto_now_add=True)

class Tag(db.Model):
    tag = db.StringProperty(multiline=False)
    entrycount = db.IntegerProperty(default=0)
    valid = db.BooleanProperty(default = True)

class Post(db.Model):
    title = db.StringProperty(required=True)
    content = db.TextProperty(required=True)
    date = db.DateTimeProperty(auto_now_add=True)
    author = db.UserProperty()
    authorEmail = db.EmailProperty(required=True)
    catalog = db.StringProperty()
    tags = db.ListProperty(db.Category)
    permalink = db.StringProperty()
    lastCommentedDate = db.DateTimeProperty()
    commentcount = db.IntegerProperty(default=0)
    lastModifiedDate = db.DateTimeProperty()
    lastModifiedBy = db.UserProperty()
    
class Comment(db.Model):
    post = db.ReferenceProperty(Post)
    user = db.StringProperty(required=True)
    date = db.DateTimeProperty(auto_now_add=True)
    author = db.UserProperty()
    authorEmail = db.EmailProperty(required=True)
    authorWebsite = db.StringProperty()
    userIp = db.StringProperty()
    content = db.TextProperty(required=True)
    lastModifiedDate = db.DateTimeProperty()
    lastModifiedBy = db.UserProperty()

    def save(self):
        self.put()
        if self.post :
            self.post.lastCommentedDate = self.date
            self.post.commentcount += 1
            self.post.put()

